'use strict'
let path = require('path');
let ProjectCore = require('project-core');
let createDebug = require('debug');
const $ = global.$ = new ProjectCore();
//打印日志
$.createDebug=function (name) {
	return createDebug('my:'+name);
}
//初始化配置对象 添加函数
$.init.add(done => {
	$.config.load(path.resolve(__dirname,'config.js'));
	const env=process.env.NODE_ENV;
	if (env) {
		$.config.load(path.resolve(__dirname,'../config',env+'.js'));
	}
	$.env=env;
	done();
});
//加载文件或文件夹的方式添加函数
$.init.load(path.resolve(__dirname,'init','mongodb.js'));
$.init.load(path.resolve(__dirname,'models'));
$.init.load(path.resolve(__dirname,'methods'));
$.init.load(path.resolve(__dirname,'init','express.js'));
$.init.load(path.resolve(__dirname,'middlewares'));

$.init.load(path.resolve(__dirname,'routes'));
$.init(err => {
	if (err) {
		console.error(err);
		process.exit(-1);
	} else {
		console.log('inited');
	}
});